package com.example.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.ComRecruit;
import com.example.entity.Delivery;
import com.example.entity.Diary;
import com.example.entity.StuDelivery;
import org.springframework.boot.convert.Delimiter;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义List分页工具
 * @author hanwl
 */
public class PageUtils {

    /**
     * 对list数据进行分页
     * @param pageNum
     * @param pageSize
     * @param dtoList
     * @return
     */
    public IPage<ComRecruit> getcomRecruitPage(Integer pageNum, Integer pageSize, List<ComRecruit> dtoList){
        List<ComRecruit> pageList = new ArrayList<>();

        int index= pageNum > 1 ? (pageNum - 1) * pageSize : 0;
        for (int i = 0; i < pageSize && index+ i < dtoList.size(); i++){
            pageList.add(dtoList.get(index+i));
        }

        IPage<ComRecruit> dtoPage = new Page<>(pageNum, pageSize);
        dtoPage.setRecords(pageList);
        dtoPage.setTotal(dtoList.size());
        return dtoPage;
    }

    public IPage<StuDelivery> getstuDeliveryPage(Integer pageNum, Integer pageSize, List<StuDelivery> dtoList){
        List<StuDelivery> pageList = new ArrayList<>();


        int index= pageNum > 1 ? (pageNum - 1) * pageSize : 0;
        for (int i = 0; i < pageSize && index+ i < dtoList.size(); i++){
            pageList.add(dtoList.get(index+i));
        }

        IPage<StuDelivery> dtoPage = new Page<>(pageNum, pageSize);
        dtoPage.setRecords(pageList);
        dtoPage.setTotal(dtoList.size());
        return dtoPage;
    }

    public IPage<Diary> getDiaryPage(Integer pageNum, Integer pageSize, List<Diary> dtoList){
        List<Diary> pageList = new ArrayList<>();


        int index= pageNum > 1 ? (pageNum - 1) * pageSize : 0;
        for (int i = 0; i < pageSize && index+ i < dtoList.size(); i++){
            pageList.add(dtoList.get(index+i));
        }

        IPage<Diary> dtoPage = new Page<>(pageNum, pageSize);
        dtoPage.setRecords(pageList);
        dtoPage.setTotal(dtoList.size());
        return dtoPage;
    }

}
